﻿@{
    ViewBag.Title = "短信发送黑名单日期";
    Layout = "~/Views/Shared/_layer.cshtml";
}


@model YouWei.Infrastructure.Entity.SmsBlackDay

@section style{
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }
    </style>
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">日期类型：</label>
                        <div class="col-sm-3">
                            @if (Model.DayID > 0)
                            {
                                foreach (int v in Enum.GetValues(typeof(YouWei.Infrastructure.Enums.SmsDateTypeEnum)))
                                {
                                    if (v == Model.DateType)
                                    {
                                        <input type="radio" name="selDateType" value="@v" checked="checked" />
                                        @YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.SmsDateTypeEnum), v)
                                    }
                                    else
                                    {
                                        <input type="radio" name="selDateType" value="@v" />
                                        @YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.SmsDateTypeEnum), v)
                                    }
                                }
                            }
                            else
                            {
                                foreach (int v in Enum.GetValues(typeof(YouWei.Infrastructure.Enums.SmsDateTypeEnum)))
                                {
                                    if (v == 1)
                                    {
                                        <input type="radio" name="selDateType" value="@v" checked="checked" />
                                        @YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.SmsDateTypeEnum), v)
                                    }
                                    else
                                    {
                                        <input type="radio" name="selDateType" value="@v" />
                                        @YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.SmsDateTypeEnum), v)
                                    }
                                }
                            }
                        </div>
                    </div>
                    @if (Model.DayID > 0)
                    {
                        if (Model.DateType == 1)
                        {
                            <div class="form-group" id="weekDiv">
                                <label class="col-sm-2 control-label" for="name">日期值：</label>
                                <div class="col-sm-3">
                                    @foreach (int v in Enum.GetValues(typeof(YouWei.Infrastructure.Enums.SmsWeekEnum)))
                                    {
                                        if (v == Model.DateValue)
                                        {
                                            <input type="radio" name="weekValue" value="@v" checked="checked" />
                                            @YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.SmsWeekEnum), v)
                                        }
                                        else
                                        {
                                            <input type="radio" name="weekValue" value="@v" />
                                            @YouWei.Utility.EnumHelper.GetEnumDesc(typeof(YouWei.Infrastructure.Enums.SmsWeekEnum), v)
                                        }
                                    }
                                </div>
                            </div>
                            <div class="form-group" id="dateDiv" style="display:none;">
                                <label class="col-sm-2 control-label" for="name">日期值：</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" value="" style="width:300px;" name="txtDateValue" maxlength="10" id="txtDateValue" autocomplete="off" />
                                </div>
                            </div>
                        }
                        else
                        {
                            <div class="form-group" id="weekDiv" style="display:none;">
                                <label class="col-sm-2 control-label" for="name">日期值：</label>
                                <div class="col-sm-3">
                                    <input type="radio" value="1" name="weekValue" />周一
                                    <input type="radio" value="2" name="weekValue" />周二
                                    <input type="radio" value="3" name="weekValue" />周三
                                    <input type="radio" value="4" name="weekValue" />周四
                                    <input type="radio" value="5" name="weekValue" />周五
                                    <input type="radio" value="6" name="weekValue" />周六
                                    <input type="radio" value="7" name="weekValue" />周七
                                </div>
                            </div>
                            <div class="form-group" id="dateDiv">
                                <label class="col-sm-2 control-label" for="name">日期值：</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" value="@Model.DateValue.ToString().Insert(4,"-").Insert(7,"-")" style="width:300px;" name="txtDateValue" maxlength="10" id="txtDateValue" autocomplete="off" />
                                </div>
                            </div>
                        }

                    }
                    else
                    {
                        <div class="form-group" id="weekDiv">
                            <label class="col-sm-2 control-label" for="name">日期值：</label>
                            <div class="col-sm-3">
                                <input type="radio" value="1" name="weekValue" />周一
                                <input type="radio" value="2" name="weekValue" />周二
                                <input type="radio" value="3" name="weekValue" />周三
                                <input type="radio" value="4" name="weekValue" />周四
                                <input type="radio" value="5" name="weekValue" />周五
                                <input type="radio" value="6" name="weekValue" />周六
                                <input type="radio" value="7" name="weekValue" />周七
                            </div>
                        </div>
                        <div class="form-group" id="dateDiv" style="display:none;">
                            <label class="col-sm-2 control-label" for="name">日期值：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" value="" style="width:300px;" name="txtDateValue" maxlength="10" id="txtDateValue" autocomplete="off" />
                            </div>
                        </div>
                       
                    }
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                    <input type="hidden" id="dayId" name="dayId" value="@Model.DayID" />
                    <input type="hidden" id="taskId" name="taskId" value="@ViewBag.TaskId" />
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script type="text/javascript">
       $(document).ready(function () {
           initFormValidate();
           $("#txtDateValue").datepicker({
               language: "zh-CN",
               autoclose: true,//选中之后自动隐藏日期选择框
               format: "yyyy-mm-dd"//日期格式，
           });
           $("#btnSave").click(function(){
               save();
           });
           $("#cancel").click(function () {
               BMCW.closeAll();
           });
           
           $("input[name='selDateType']").click(function () {
               if ($(this).val() == 1) {
                   $("#weekDiv").show();
                   $("#dateDiv").hide();
               } else {
                   $("#weekDiv").hide();
                   $("#dateDiv").show();
               }
           })
       });
       function initFormValidate() {
           $("#form1").bootstrapValidator({
               submitHandler: function (valiadtor, loginForm, submitButton) {
                   valiadtor.defaultSubmit();
               },
               fields: {
                   selDateType: {
                       validators: {
                           notEmpty: {
                               message: '请选择分类'
                           }
                       }
                   },
                   txtDateValue: {
                       validators: {
                           notEmpty: {
                               message: '日期值不能为空'
                           }
                       }
                   },
                   weekValue: {
                       validators: {
                           notEmpty: {
                               message: "日期值不能为空",
                               callback: function () {
                                   if ($("input[name='selDateType']:checked").val() == 1) {
                                       return false;
                                   }
                                   return true;
                               }
                           }
                       }
                   }
               }
           });
       }

       function save()
       {
           var bootstrapValidator = $("#form1").data('bootstrapValidator');
           bootstrapValidator.validate();

           if (bootstrapValidator.isValid()) {
               var url = '@Url.Action("SaveBlackDay", "Sms")';
               var val = '';
               if ($("input[name='selDateType']:checked").val() == 1) {
                   val = $("input[name='weekValue']:checked").val();
               } else {
                   val = $("#txtDateValue").val();
               }
               BMCW.ajax({
                   url: url,
                   type: "POST",
                   data: {
                       TaskID: $("#taskId").val(),
                       DayID: $("#dayId").val(),
                       DateType: $("input[name='selDateType']:checked").val(),
                       DateValue: val
                   },
                   success: function (o) {
                       if (o.status == 0) {
                           BMCW.msg("保存成功",function(){
                               BMCW.closeAll();
                               parent.search();
                           });
                       } else {
                           BMCW.alert("保存失败");
                       }
                   }
               });
           }
       }

    </script>
}
